﻿namespace LeetCode_Learn
{
    public class Compare
    {
        public static void DO(int number, Action<int[]> CustomSort, int length, int min, int max)
        {
            if (number == 0) return;

            for (int i = 0; i < number; i++)
            {
                DO(CustomSort, length, min, max);
            }
        }

        static bool DO(Action<int[]> CustomSort, int length, int min, int max)
        {
            int[] arr = new int[length];
            RandomArr(arr, length, min, max);

            int[] arr1 = new int[length];
            Array.Copy(arr, arr1, length);

            int[] arr2 = new int[length];
            Array.Copy(arr, arr2, length);

            Array.Sort(arr1);
            CustomSort(arr2);

            if (!Do(arr1, arr2, length))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"错误样本{string.Join(", ", arr)}");
                Console.WriteLine($"错误样本排序: {string.Join(", ", arr2)}");
                Console.WriteLine("\n");
                return false;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"正确样本{string.Join(", ", arr)}");
                Console.WriteLine($"正确样本排序{string.Join(", ", arr2)}");
                Console.WriteLine("\n");
            };

            Console.ForegroundColor = ConsoleColor.White;
            return true;
        }

        static bool Do(int[] arr1, int[] arr2, int length)
        {
            bool right = true;
            for (int i = 0; i < length; i++)
            {
                if (arr1[i] == arr2[i])
                {

                }
                else
                {
                    right = false;
                };
            }
            return right;
        }

        static void RandomArr(int[] arr, int length, int min, int max)
        {
            Random rand = new Random();
            for (int i = 0; i < length; i++)
            {
                arr[i] = rand.Next(min, max);
            }
        }
    }
}
